Imports System

Imports DotNetNuke
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities.Modules

Namespace TressleWorks.Modules.ThermoChart

    Public Class ThermoChartInfo

        Private bShowBulb As Boolean
        Private bShowValue As Boolean
        Private bShowValueAsPercent As Boolean
        Private bShowRoundedTip As Boolean
        Private bShowShadow As Boolean
        Private bShowMain As Boolean
        Private bShowLines As Boolean
        Private bShowSQLCommand As Boolean
        Private bShowGradientOverRange As Boolean

        Private sFilename As String
        Private sTitle As String
        Private oTitleFontSettings As FontSettings
        Private oScaleFontSettings As FontSettings
        Private oValueFontSettings As FontSettings

        Private oMercuryColourSettings As ColourSettings
        Private oMercuryShadowSettings As ColourSettings

        Private oBackGroundSettings As ColourSettings

        Private iWidth As Integer
        Private iHeight As Integer

        Private iBarWidth As Integer
        Private iBarHeight As Integer

        Private iMajorMarkerCount As Integer
        Private iMinorMarkerCount As Integer

        Private dMinValue As Decimal
        Private dMaxValue As Decimal
        Private dCurrentValue As Decimal

        Private iMajorMarkerWidth As Integer
        Private iMinorMarkerWidth As Integer
        Private iMarkerMargin As Integer

        Private iMarginLeft As Integer
        Private iMarginRight As Integer
        Private iMarginTop As Integer
        Private iMarginBottom As Integer

        Private iCenterLineAdjust As Integer    ' +ve moves to right, -ve to the left

        Private eScaleLocation As ScaleLocationType

        Private eValueFormat As ValueFormatType
        Private sValueFormatString As String
        Private sScaleFormatString As String

        Private sHeader As String
        Private sFooter As String

        Private sIMCParameterName As String

        Private bEnableSQL As Boolean
        Private bEnableMatrix As Boolean
        Private iMatrixRows As Integer
        Private iMatrixColumns As Integer
        Private sSQLCommand As String
        Private sConnectionString As String


        Private iModuleID As Integer
        Private oContainer As PortalModuleBase
        Private oModuleInfo As ModuleInfo
        Private oModuleController As ModuleController
        Private oModuleSettings As Hashtable

        Public Enum ScaleLocationType As Integer
            None = 0
            Left = 1
            Right = 2
        End Enum

        Public Enum ValueFormatType As Integer
            [UserDefined] = 0
            [Currency] = 1
            [Decimal] = 2
            [Integer] = 3
        End Enum

        'Public Sub New()
        '    Call Initialize()
        'End Sub

        Public Sub New(ByVal poContainer As PortalModuleBase)
            Call Initialize(poContainer)
        End Sub

        Public Sub New(ByVal poContainer As PortalModuleBase, ByVal psfilename As String, ByVal psTitle As String, ByVal pdMinValue As Decimal, ByVal pdMaxValue As Decimal, ByVal pdCurrentValue As Decimal, ByVal peType As ValueFormatType)
            Call Initialize(poContainer)

            sFilename = psfilename
            sTitle = psTitle

            dMinValue = pdMinValue
            dMaxValue = pdMaxValue
            dCurrentValue = pdCurrentValue

            eValueFormat = peType

        End Sub

        Private Sub Initialize(ByVal poContainer As PortalModuleBase)
            'Private Sub Initialize()

            bShowBulb = True
            bShowValue = True
            bShowShadow = True
            bShowMain = True
            bShowLines = False
            bShowSQLCommand = False
            bShowValueAsPercent = False
            bShowGradientOverRange = False

            sFilename = String.Empty
            sTitle = String.Empty

            dMinValue = 0
            dMaxValue = 0
            dCurrentValue = -12345
            iWidth = 240
            iHeight = 400

            iBarWidth = -1      'default    
            iBarHeight = -1     'default

            iMajorMarkerCount = 10
            iMinorMarkerCount = 3

            iMajorMarkerWidth = 15
            iMinorMarkerWidth = 10
            iMarkerMargin = 2

            iMarginLeft = 0
            iMarginRight = 0
            iMarginTop = 0
            iMarginBottom = 0

            iCenterLineAdjust = 0

            eValueFormat = ValueFormatType.Integer
            sValueFormatString = String.Empty
            sScaleFormatString = String.Empty

            eScaleLocation = ScaleLocationType.Left

            oTitleFontSettings = New FontSettings()
            oScaleFontSettings = New FontSettings()
            oValueFontSettings = New FontSettings()

            oMercuryColourSettings = New ColourSettings("Red")
            oMercuryShadowSettings = New ColourSettings("Sliver")
            oBackGroundSettings = New ColourSettings("White")

            sHeader = String.Empty
            sFooter = String.Empty

            sIMCParameterName = String.Empty

            bEnableSQL = False
            bEnableMatrix = False
            iMatrixColumns = 0
            iMatrixRows = 0
            sSQLCommand = String.Empty
            sConnectionString = String.Empty

            oContainer = poContainer
            iModuleID = oContainer.ModuleId

            oModuleController = New ModuleController
            oModuleInfo = oModuleController.GetModule(oContainer.ModuleId, oContainer.TabId, False)
            oModuleSettings = oModuleController.GetModuleSettings(oContainer.ModuleId)

        End Sub

#Region "Properities"

        Public Property ShowBulb() As Boolean
            Get
                Return bShowBulb
            End Get
            Set(ByVal value As Boolean)
                bShowBulb = value
            End Set
        End Property

        Public Property ShowValue() As Boolean
            Get
                Return bShowValue
            End Get
            Set(ByVal value As Boolean)
                bShowValue = value
            End Set
        End Property

        Public Property ShowValueAsPercent() As Boolean
            Get
                Return bShowValueAsPercent
            End Get
            Set(ByVal value As Boolean)
                bShowValueAsPercent = value
            End Set
        End Property


        Public Property ShowShadow() As Boolean
            Get
                Return bShowShadow
            End Get
            Set(ByVal value As Boolean)
                bShowShadow = value
            End Set
        End Property

        Public Property ShowMain() As Boolean
            Get
                Return bShowMain
            End Get
            Set(ByVal value As Boolean)
                bShowMain = value
            End Set
        End Property


        Public Property ShowLines() As Boolean
            Get
                Return bShowLines
            End Get
            Set(ByVal value As Boolean)
                bShowLines = value
            End Set
        End Property

        Public Property ShowRoundedTip() As Boolean
            Get
                Return bShowRoundedTip
            End Get
            Set(ByVal value As Boolean)
                bShowRoundedTip = value
            End Set
        End Property

        Public Property ShowGradientOverRange() As Boolean
            Get
                Return bShowGradientOverRange
            End Get
            Set(ByVal value As Boolean)
                bShowGradientOverRange = value
            End Set
        End Property

        Public Property Filename() As String
            Get
                Return sFilename
            End Get
            Set(ByVal value As String)
                sFilename = value
            End Set
        End Property

        Public Property Title() As String
            Get
                Return sTitle
            End Get
            Set(ByVal value As String)
                sTitle = value
            End Set
        End Property

        Public Property TitleFontSettingsString() As String
            Get
                Return oTitleFontSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oTitleFontSettings.Parse(value)
            End Set
        End Property

        Public Property TitleFontSettings() As FontSettings
            Get
                Return oTitleFontSettings
            End Get
            Set(ByVal value As FontSettings)
                oTitleFontSettings = value
            End Set
        End Property


        Public Property MinValue() As Decimal
            Get
                Return dMinValue
            End Get
            Set(ByVal value As Decimal)
                dMinValue = value
            End Set
        End Property

        Public Property MaxValue() As Decimal
            Get
                Return dMaxValue
            End Get
            Set(ByVal value As Decimal)
                dMaxValue = value
            End Set
        End Property

        Public Property MajorMarkerCount() As Integer
            Get
                Return iMajorMarkerCount
            End Get
            Set(ByVal value As Integer)
                iMajorMarkerCount = value
            End Set
        End Property

        Public Property MinorMarkerCount() As Integer
            Get
                Return iMinorMarkerCount
            End Get
            Set(ByVal value As Integer)
                iMinorMarkerCount = value
            End Set
        End Property

        Public Property ScaleFontSettingsString() As String
            Get
                Return oScaleFontSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oScaleFontSettings.Parse(value)
            End Set
        End Property

        Public Property ScaleFontSettings() As FontSettings
            Get
                Return oScaleFontSettings
            End Get
            Set(ByVal value As FontSettings)
                oScaleFontSettings = value
            End Set
        End Property

        Public Property ScaleFormatString() As String
            Get
                Return sScaleFormatString
            End Get
            Set(ByVal value As String)
                sScaleFormatString = value
            End Set
        End Property

        Public Property CurrentValue() As Decimal
            Get
                Return dCurrentValue
            End Get
            Set(ByVal value As Decimal)
                dCurrentValue = value
            End Set
        End Property

        Public Property ValueFontSettingsString() As String
            Get
                Return oValueFontSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oValueFontSettings.Parse(value)
            End Set
        End Property

        Public Property ValueFontSettings() As FontSettings
            Get
                Return oValueFontSettings
            End Get
            Set(ByVal value As FontSettings)
                oValueFontSettings = value
            End Set
        End Property

        Public Property ValueFormatString() As String
            Get
                Return sValueFormatString
            End Get
            Set(ByVal value As String)
                sValueFormatString = value
            End Set
        End Property

        Public Property Width() As Integer
            Get
                Return iWidth
            End Get
            Set(ByVal value As Integer)
                iWidth = value
            End Set
        End Property

        Public Property Height() As Integer
            Get
                Return iHeight
            End Get
            Set(ByVal value As Integer)
                iHeight = value
            End Set
        End Property

        Public Property BarWidth() As Integer
            Get
                Return iBarWidth
            End Get
            Set(ByVal value As Integer)
                iBarWidth = value
            End Set
        End Property

        Public Property BarHeight() As Integer
            Get
                Return iBarHeight
            End Get
            Set(ByVal value As Integer)
                iBarHeight = value
            End Set
        End Property

        Public Property ScaleLocation() As ScaleLocationType
            Get
                Return eScaleLocation
            End Get
            Set(ByVal value As ScaleLocationType)
                eScaleLocation = value
            End Set
        End Property

        Public Property ValueFormat() As ValueFormatType
            Get
                Return eValueFormat
            End Get
            Set(ByVal value As ValueFormatType)
                eValueFormat = value
            End Set
        End Property

        Public Property MarginLeft() As Integer
            Get
                Return iMarginLeft
            End Get
            Set(ByVal value As Integer)
                iMarginLeft = value
            End Set
        End Property

        Public Property MarginRight() As Integer
            Get
                Return iMarginRight
            End Get
            Set(ByVal value As Integer)
                iMarginRight = value
            End Set
        End Property

        Public Property MarginTop() As Integer
            Get
                Return iMarginTop
            End Get
            Set(ByVal value As Integer)
                iMarginTop = value
            End Set
        End Property

        Public Property MarginBottom() As Integer
            Get
                Return iMarginBottom
            End Get
            Set(ByVal value As Integer)
                iMarginBottom = value
            End Set
        End Property

        Public Property MarginSizeString() As String
            Get
                Dim stemp As String = String.Empty
                stemp &= MarginTop.ToString & ","
                stemp &= MarginRight.ToString & ","
                stemp &= MarginBottom.ToString & ","
                stemp &= MarginLeft.ToString
                Return stemp
            End Get

            Set(ByVal value As String)
                If value.Length = 0 Then
                    Exit Property
                End If
                'top,right,bottom,left
                Dim sparts() As String = Split(value, ",")
                If sparts.Length > 0 Then
                    iMarginTop = Val(sparts(0))
                    If sparts.Length > 1 Then
                        iMarginRight = Val(sparts(1))
                        If sparts.Length > 2 Then
                            iMarginBottom = Val(sparts(2))
                            If sparts.Length > 3 Then
                                iMarginLeft = Val(sparts(3))
                            End If
                        End If
                    End If
                End If
            End Set
        End Property

        Public Property CenterLineAdjust() As Integer
            Get
                Return iCenterLineAdjust
            End Get
            Set(ByVal value As Integer)
                iCenterLineAdjust = value
            End Set
        End Property
      
        Public Property MercuryColourSettingsString() As String
            Get
                Return oMercuryColourSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oMercuryColourSettings.Parse(value)
            End Set
        End Property

        Public Property MercuryColourSettings() As ColourSettings
            Get
                Return oMercuryColourSettings
            End Get
            Set(ByVal value As ColourSettings)
                oMercuryColourSettings = value
            End Set
        End Property

        Public Property MercuryShadowSettingsString() As String
            Get
                Return oMercuryShadowSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oMercuryShadowSettings.Parse(value)
            End Set
        End Property

        Public Property MercuryShadowSettings() As ColourSettings
            Get
                Return oMercuryShadowSettings
            End Get
            Set(ByVal value As ColourSettings)
                oMercuryShadowSettings = value
            End Set
        End Property

        Public Property BackGroundSettingsString() As String
            Get
                Return oBackGroundSettings.SettingString
            End Get
            Set(ByVal value As String)
                Call oBackGroundSettings.Parse(value)
            End Set
        End Property

        Public Property BackGroundSettings() As ColourSettings
            Get
                Return oBackGroundSettings
            End Get
            Set(ByVal value As ColourSettings)
                oBackGroundSettings = value
            End Set
        End Property

        Public Property Header() As String
            Get
                Return sHeader
            End Get
            Set(ByVal value As String)
                sHeader = value
            End Set
        End Property

        Public Property Footer() As String
            Get
                Return sFooter
            End Get
            Set(ByVal value As String)
                sFooter = value
            End Set
        End Property

        Public Property IMCParameterName() As String
            Get
                Return sIMCParameterName
            End Get
            Set(ByVal value As String)
                sIMCParameterName = value.Trim
                If Not (sIMCParameterName.StartsWith("[") And sIMCParameterName.EndsWith("]")) Then
                    sIMCParameterName = "[" & sIMCParameterName & "]"
                End If
            End Set
        End Property

        Public Property SQLCommand() As String
            Get
                Return sSQLCommand
            End Get
            Set(ByVal value As String)
                sSQLCommand = value
            End Set
        End Property

        Public Property ConnectionString() As String
            Get
                Return sConnectionString
            End Get
            Set(ByVal value As String)
                sConnectionString = value
            End Set
        End Property

        Public Property EnableSQL() As Boolean
            Get
                Return bEnableSQL
            End Get
            Set(ByVal value As Boolean)
                bEnableSQL = value
            End Set
        End Property

        Public Property EnableMatrix() As Boolean
            Get
                Return bEnableMatrix
            End Get
            Set(ByVal value As Boolean)
                bEnableMatrix = value
            End Set
        End Property

        Public Property MatrixRows() As Integer
            Get
                Return iMatrixRows
            End Get
            Set(ByVal value As Integer)
                iMatrixRows = value
            End Set
        End Property

        Public Property MatrixColumns() As Integer
            Get
                Return iMatrixColumns
            End Get
            Set(ByVal value As Integer)
                iMatrixColumns = value
            End Set
        End Property

        Public Property ShowSQLCommand() As Boolean
            Get
                Return bShowSQLCommand
            End Get
            Set(ByVal value As Boolean)
                bShowSQLCommand = value
            End Set
        End Property

        Public Property MajorMarkerWidth() As Integer
            Get
                Return iMajorMarkerWidth
            End Get
            Set(ByVal value As Integer)
                iMajorMarkerWidth = value
            End Set
        End Property

        Public Property MinorMarkerWidth() As Integer
            Get
                Return iMinorMarkerWidth
            End Get
            Set(ByVal value As Integer)
                iMinorMarkerWidth = value
            End Set
        End Property

        Public Property MarkerMargin() As Integer
            Get
                Return iMarkerMargin
            End Get
            Set(ByVal value As Integer)
                iMarkerMargin = value
            End Set
        End Property

        Public Property MarkerSizeString() As String
            Get
                Dim stemp As String = String.Empty
                stemp &= MajorMarkerWidth.ToString & ","
                stemp &= MinorMarkerWidth.ToString & ","
                stemp &= MarkerMargin.ToString
                Return stemp
            End Get

            Set(ByVal value As String)
                If value.Length = 0 Then
                    Exit Property
                End If
                Dim sparts() As String = Split(value, ",")
                If sparts.Length > 0 Then
                    iMajorMarkerWidth = Val(sparts(0))
                    If sparts.Length > 1 Then
                        iMinorMarkerWidth = Val(sparts(1))
                        If sparts.Length > 2 Then
                            iMarkerMargin = Val(sparts(2))
                        End If
                    End If
                End If
            End Set
        End Property

        Public ReadOnly Property CurrentPercent() As Decimal
            Get
                Dim dAdjValue As Decimal = dCurrentValue
                Dim dPercent As Decimal = 0

                If dCurrentValue < dMinValue Then
                    dAdjValue = dMinValue
                ElseIf dCurrentValue > dMaxValue Then
                    dAdjValue = dMaxValue
                Else
                    dAdjValue = dCurrentValue - dMinValue
                End If

                dPercent = dAdjValue / (dMaxValue - dMinValue)
                If dPercent < 0 Then dPercent = 0
                If dPercent > 1 Then dPercent = 1

                Return dPercent
            End Get
        End Property

#End Region

#Region "Public Routines"

        Public Function IsNewChart() As Boolean
            If dCurrentValue = -12345 Then
                Return True
            Else
                Return False
            End If
        End Function

        Public Function CurrentValueToText() As String
            Return ValueToText(dCurrentValue)
        End Function

        Public Function ValueToText(ByVal dValue As Decimal, Optional ByVal psFormat As String = "") As String
            Dim sText As String = ""

            If psFormat.Length > 0 Then
                Try
                    Return String.Format(psFormat, dValue)
                Catch ex As Exception
                    Return ex.Message
                End Try
            End If

            Select Case eValueFormat

                Case ThermoChartInfo.ValueFormatType.UserDefined
                    If sValueFormatString.Length > 0 Then
                        Try
                            sText = String.Format(sValueFormatString, dValue)
                        Catch ex As Exception
                            sText = ex.Message
                        End Try
                    Else
                        sText = String.Format("{0:d}", dValue)
                    End If

                Case ThermoChartInfo.ValueFormatType.Currency
                    sText = FormatCurrency(dValue, 2, TriState.True, TriState.True, TriState.True)

                Case ThermoChartInfo.ValueFormatType.Decimal
                    sText = FormatNumber(dValue, 2, TriState.True, TriState.True, TriState.True)

                Case ThermoChartInfo.ValueFormatType.Integer
                    sText = CInt(dValue)

            End Select

            Return sText
        End Function

        Public Function SubstituteParms(ByVal psText) As String

            psText = Replace(psText, "[Value]", CurrentValueToText, , , CompareMethod.Text)
            psText = Replace(psText, "[Percent]", String.Format("{0:p}", CurrentPercent), , , CompareMethod.Text)
            psText = Replace(psText, "[MinValue]", String.Format("{0:p}", ValueToText(dMinValue)), , , CompareMethod.Text)
            psText = Replace(psText, "[MaxValue]", String.Format("{0:p}", ValueToText(dMaxValue)), , , CompareMethod.Text)

            Return psText
        End Function


        Public Sub Load()

            bShowBulb = CBool(GetSettings("ShowBulb", "True"))
            bShowValue = CBool(GetSettings("ShowValue", "True"))
            bShowValueAsPercent = CBool(GetSettings("ShowValueAsPercent", "False"))
            bShowRoundedTip = CBool(GetSettings("ShowRoundedTip", "True"))
            bShowShadow = CBool(GetSettings("ShowShadow", "True"))
            bShowMain = CBool(GetSettings("ShowMain", "True"))
            bShowLines = CBool(GetSettings("ShowLines", "False"))
            bShowSQLCommand = CBool(GetSettings("ShowSQLCommand", "False"))
            bShowGradientOverRange = CBool(GetSettings("ShowGradientOverRange", "False"))

            sTitle = GetSettings("Title")
            Call oTitleFontSettings.Parse(GetSettings("TitleFontSettings"))
            Call oScaleFontSettings.Parse(GetSettings("ScaleFontSettings"))
            Call oValueFontSettings.Parse(GetSettings("ValueFontSettings"))

            Call oMercuryColourSettings.Parse(GetSettings("MercuryColourSettings"))
            Call oMercuryShadowSettings.Parse(GetSettings("MercuryShadowSettings"))
            Call oBackGroundSettings.Parse(GetSettings("BackGroundSettings"))

            iMinorMarkerCount = Val(GetSettings("MinorMarkerCount", "3"))
            iMajorMarkerCount = Val(GetSettings("MajorMarkerCount", "10"))

            iMajorMarkerWidth = Val(GetSettings("MajorMarkerWidth", "15"))
            iMinorMarkerWidth = Val(GetSettings("MinorMarkerWidth", "10"))
            iMarkerMargin = Val(GetSettings("MarkerMargin", "2"))

            dMinValue = Val(GetSettings("MinValue", "0"))
            dMaxValue = Val(GetSettings("MaxValue", "100"))
            dCurrentValue = Val(GetSettings("CurrentValue", dCurrentValue.ToString))

            iHeight = Val(GetSettings("Height"))
            iWidth = Val(GetSettings("Width"))

            iBarHeight = Val(GetSettings("BarHeight"))
            iBarWidth = Val(GetSettings("BarWidth"))

            iMarginLeft = Val(GetSettings("MarginLeft"))
            iMarginRight = Val(GetSettings("MarginRight"))
            iMarginTop = Val(GetSettings("MarginTop"))
            iMarginBottom = Val(GetSettings("MarginBottom"))

            iCenterLineAdjust = Val(GetSettings("CenterLineAdjust"))

            eScaleLocation = System.Enum.Parse(GetType(ScaleLocationType), GetSettings("ScaleLocation", "Left"))  'default to Left

            eValueFormat = System.Enum.Parse(GetType(ValueFormatType), GetSettings("ValueFormatType", "Integer"))  'default to Integer
            sValueFormatString = GetSettings("ValueFormat", "{0:d}")
            sScaleFormatString = GetSettings("ScaleFormat")

            sHeader = GetSettings("Header")
            sFooter = GetSettings("Footer")

            bEnableSQL = CBool(GetSettings("EnableSQL", "False"))
            bEnableMatrix = CBool(GetSettings("EnableMatrix", "False"))

            iMatrixColumns = Val(GetSettings("MatrixColumns", "0"))
            iMatrixRows = Val(GetSettings("MatrixRows", "0"))

            sSQLCommand = GetSettings("SQLCommand")
            sConnectionString = GetSettings("ConnectionString")

            sIMCParameterName = GetSettings("IMCParameterName")

        End Sub

        Public Sub Save()

            Call SaveSetting("ShowBulb", bShowBulb.ToString)
            Call SaveSetting("ShowValue", bShowValue.ToString)
            Call SaveSetting("ShowValueAsPercent", bShowValueAsPercent.ToString)
            Call SaveSetting("ShowRoundedTip", bShowRoundedTip.ToString)
            Call SaveSetting("ShowShadow", bShowShadow.ToString)
            Call SaveSetting("ShowMain", bShowMain.ToString)
            Call SaveSetting("ShowLines", bShowLines.ToString)
            Call SaveSetting("ShowSQLCommand", bShowSQLCommand.ToString)
            Call SaveSetting("ShowGradientOverRange", bShowGradientOverRange.ToString)

            Call SaveSetting("Title", sTitle)
            Call SaveSetting("TitleFontSettings", oTitleFontSettings.SettingString)

            Call SaveSetting("ScaleFontSettings", oScaleFontSettings.SettingString)
            Call SaveSetting("ValueFontSettings", oValueFontSettings.SettingString)

            Call SaveSetting("MercuryColourSettings", oMercuryColourSettings.SettingString)
            Call SaveSetting("MercuryShadowSettings", oMercuryShadowSettings.SettingString)
            Call SaveSetting("BackGroundSettings", oBackGroundSettings.SettingString)

            Call SaveSetting("MinorMarkerCount", iMinorMarkerCount.ToString)
            Call SaveSetting("MajorMarkerCount", iMajorMarkerCount.ToString)

            Call SaveSetting("MajorMarkerWidth", iMajorMarkerWidth.ToString)
            Call SaveSetting("MinorMarkerWidth", iMinorMarkerWidth.ToString)
            Call SaveSetting("MarkerMargin", iMarkerMargin.ToString)

            Call SaveSetting("MinValue", dMinValue.ToString)
            Call SaveSetting("MaxValue", dMaxValue.ToString)
            Call SaveSetting("CurrentValue", dCurrentValue.ToString)

            Call SaveSetting("Height", iHeight.ToString)
            Call SaveSetting("Width", iWidth.ToString)

            Call SaveSetting("BarHeight", iBarHeight.ToString)
            Call SaveSetting("BarWidth", iBarWidth.ToString)

            Call SaveSetting("MarginLeft", iMarginLeft.ToString)
            Call SaveSetting("MarginRight", iMarginRight.ToString)
            Call SaveSetting("MarginTop", iMarginTop.ToString)
            Call SaveSetting("MarginBottom", iMarginBottom.ToString)

            Call SaveSetting("CenterLineAdjust", iCenterLineAdjust.ToString)

            Call SaveSetting("ScaleLocation", System.Enum.GetName(GetType(ScaleLocationType), eScaleLocation))

            Call SaveSetting("ValueFormatType", System.Enum.GetName(GetType(ValueFormatType), eValueFormat))
            Call SaveSetting("ValueFormat", sValueFormatString)
            Call SaveSetting("ScaleFormat", sScaleFormatString)

            Call SaveSetting("Header", sHeader)
            Call SaveSetting("Footer", sFooter)

            Call SaveSetting("EnableSQL", bEnableSQL.ToString)
            Call SaveSetting("EnableMatrix", bEnableMatrix.ToString)

            Call SaveSetting("MatrixColumns", iMatrixColumns.ToString)
            Call SaveSetting("MatrixRows", iMatrixRows.ToString)

            Call SaveSetting("SQLCommand", sSQLCommand)
            Call SaveSetting("ConnectionString", sConnectionString)

            Call SaveSetting("IMCParameterName", sIMCParameterName)
        End Sub
#End Region

#Region "Private Routines"
       
        Private Function GetSettings(ByVal psSettingName As String, Optional ByVal psDefault As String = "") As String
            Dim sValue As String

            psSettingName = "TC_" + psSettingName

            Try
                If oModuleSettings Is Nothing Then
                    oModuleSettings = oModuleController.GetModuleSettings(iModuleID)
                End If

                If oModuleSettings.ContainsKey(psSettingName) Then
                    sValue = DirectCast(oModuleSettings(psSettingName), String)
                    If sValue IsNot Nothing Then
                        Return sValue
                    End If
                End If

                Return psDefault

            Catch ex As Exception
                Return psDefault
            End Try
        End Function

        Private Sub SaveSetting(ByVal psSettingName As String, ByVal ParamArray psOptions() As String)

            Dim sTemp As String = String.Empty

            For idx As Integer = 0 To psOptions.Length - 1
                If sTemp.Length > 0 Then
                    sTemp &= "|"
                End If
                sTemp &= psOptions(idx)
            Next

            psSettingName = "TC_" + psSettingName

            Call oModuleController.UpdateModuleSetting(oContainer.ModuleId, psSettingName, sTemp)

        End Sub

#End Region

    End Class

End Namespace
